package com.itheima.controller;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
/**
 * 日期控制器类
 */
@Controller
public class DateController {
	/**
	 * 使用自定义类型数据绑定日期数据
	 */
	@RequestMapping("/customDate")
	public String CustomDate(Date date) {
	    System.out.println("date="+date);
	    return "success";
	}
	
		@RequestMapping("/customDate2")
		public String CustomDate2(Date date,Model model) {
		    System.out.println("date="+date);
			model.addAttribute("datedata",date);
		    return "success_date";
		}
		@RequestMapping("/question")
		public String question1(Model model) {
			Date dNow = new Date();
			SimpleDateFormat ft1 = new SimpleDateFormat("yyyy/MM/dd");
			System.out.println( ft1.format(dNow));
		//			String date="2021-04-27";
			model.addAttribute("datedata",ft1.format(dNow));
			return "question";
		}
		
		@RequestMapping("/answer")
		public String answer1(String strDate,Model model) throws ParseException {
			Date dmil = new Date();
			SimpleDateFormat ft1 = new SimpleDateFormat("yyyy/MM/dd");
			
			SimpleDateFormat ft2 = new SimpleDateFormat("yyyy");
			System.out.println("当前年为: " + ft2.format(dmil));
			Integer year = new Integer(ft2.format(dmil));
			
			SimpleDateFormat ft3 = new SimpleDateFormat("MM");
			System.out.println("当前月为: " + ft3.format(dmil));
			Integer mon = new Integer(ft3.format(dmil));
			
			SimpleDateFormat ft4 = new SimpleDateFormat("dd");
			System.out.println("当前日为: " + ft4.format(dmil));
			Integer day = new Integer(ft4.format(dmil));
		
					
			year = year + 1000;
			System.out.println(year);
			String newdate = String.format(year+"/"+mon+"/"+day);
			System.out.println(newdate);
			
			dmil = ft1.parse(newdate);
			System.out.println(dmil);
			// a的使用，星期简称
			String str = String.format(Locale.CHINESE, "一千年以后是星期几：%ta", dmil);
			System.out.println(str);
//			System.out.println(strDate);
//			String date="星期天";
			model.addAttribute("datedata",str);
			return "answer";
		}
}
